package com.cloudfun.campusshare.service.impl;

import com.cloudfun.campusshare.RemoteAppService;
import com.cloudfun.campusshare.dto.AppDTO;
import com.cloudfun.campusshare.entity.AppEntity;
import com.cloudfun.campusshare.repo.AppEntityRepo;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created by Huqin on 2020/2/27
 */
public class RemoteAppServiceImpl implements RemoteAppService {

    @Autowired
    private AppEntityRepo appEntityRepo;

    @Override
    public AppDTO getByAppKey(String appKey) {
        AppEntity appEntity = appEntityRepo.findByAppKey(appKey);
        if (null != appEntity) {
            return new AppDTO(appEntity.getUserId(), appEntity.getId(), appEntity.getAppKey(), appEntity.getSecretKey());
        }
        appEntity = appEntityRepo.findByProdAppKey(appKey);
        if (null != appEntity) {
            return new AppDTO(appEntity.getUserId(), appEntity.getId(), appEntity.getProdAppKey(), appEntity.getProdSecretKey());
        }
        return null;
    }

}
